package com.sysu.minsysu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;

import com.sysu.R;


public class IniActivity extends Activity { 
	private Handler mHandler = new Handler();

	ImageView imageview; 
//	TextView textview; 
	int alpha = 255; 
	int b = 0; 
	public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.init);

        imageview = (ImageView) this.findViewById(R.id.ImageView01); 
//        textview = (TextView) this.findViewById(R.id.TextView01);

        Log.v("activity","start"); 
        imageview.setAlpha(alpha);

        new Thread(new Runnable() { 
            public void run() { 
//                initApp(); //初始化程序                 
                while (b < 2) { 
                    try { 
                        if (b == 0) { 
                            Thread.sleep(1500); 
                            b = 1; 
                        } else { 
                            Thread.sleep(50); 
                        }
                      //启动下一个activity
                        updateApp();
                    } catch (InterruptedException e) { 
                        e.printStackTrace(); 
                    } 
                }
            } 
        }).start();

        mHandler = new Handler() { 
            @Override 
            public void handleMessage(Message msg) { 
                super.handleMessage(msg); 
                imageview.setAlpha(alpha); 
                imageview.invalidate();
            } 
        };
    }

    public void updateApp() { 
        alpha -= 5;
        if (alpha <= 0) { 
            b = 2; 
            Intent intent = new Intent(IniActivity.this,Main.class); 
            startActivity(intent); 
            finish();
        }
        mHandler.sendMessage(mHandler.obtainMessage());
    } 
     
//    public void initApp(){ 
//         
//    } 
}